const getStyle = (obj, attr) => {
    if (obj.currentStyle) {
        return obj.currentStyle[attr];
    }

    return window.getComputedStyle(obj, null)[attr];
}

const animate = (oEle, attr, target) => {
    clearInterval(oEle.timer);
    oEle.timer = setInterval(function () {
        let current = parseInt(getStyle(oEle, attr));//当前位置
        let steps = (target - current) / 10; //有除法,就有小数点
        //把取整后的值,覆盖原来的步长
        steps = steps > 0 ? Math.ceil(steps) : Math.floor(steps);
        //步长=(目标位置-当前位置)/10;
        //新的位置=当前位置+步长   
        oEle.style[attr] = current + steps + "px";
        //清空定时器
        if (current == target) { //到家了
            clearInterval(oEle.timer);
        }
    }, 20);
}